package com.yfp.tissue.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.common.security.annotation.RequiresPermissions;
import com.yfp.tissue.domain.Dto.RouteDTO;
import com.yfp.tissue.domain.entity.Position;
import com.yfp.tissue.domain.entity.PositionSharing;
import com.yfp.tissue.service.AreaService;
import com.yfp.tissue.service.PositionService;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PROJECT_NAME: ydyfp
 * @DESCRIPTION:
 * @USER: xiaohuya
 * @DATE: 2023/12/17 15:28
 */

@RestController
@RequestMapping("/position")
@Tag(name = "点位管理")
@Slf4j
public class PositionController extends BaseController {
    @Resource
    private PositionService postionService;
    @Resource
    private AreaService areaService;


    /**
     * 点位管理条件
     */
    @GetMapping("conditionsPosition")
    @Operation(summary = "点位查询")
    @RequiresPermissions("tissue:position:query")
    public TableDataInfo queryPosition(@RequestParam(value = "companyId", required = false) String companyId
            , @RequestParam(value = "areaId", required = false) String areaId, @RequestParam(value = "routeId", required = false) String routeId
            , @RequestParam(value = "positionId", required = false) String positionId, @RequestParam(value = "typeName", required = false) String typeName
            , @RequestParam(value = "positionName", required = false) String positionName, @RequestParam(value = "enable", required = false) String enable
            , @RequestParam(value = "cityName", required = false) String cityName, @RequestParam(value = "label", required = false) Integer label) {
        RouteDTO routeDTO = new RouteDTO();
        routeDTO.setRouteId(routeId);
        routeDTO.setCompanyId(companyId);
        routeDTO.setAreaId(areaId);
        routeDTO.setEnable(enable);
        routeDTO.setPositionId(positionId);
        routeDTO.setPositionType(typeName);
        routeDTO.setPositionName(positionName);
        routeDTO.setCityName(cityName);
        routeDTO.setLabel(label);
        startPage();
        return getDataTable(postionService.queryPosition(routeDTO));
    }

    /**
     * 线路添加
     */
    @PostMapping("addPosition")
    @Operation(summary = "点位添加")
    @RequiresPermissions("tissue:position:add")

    public R addPosition(@RequestBody Position position) {
        return postionService.addPosition(position);

    }

    /**
     * 点位详情
     */
    @GetMapping("positionDetail")
    @Operation(summary = "点位详情")
    @RequiresPermissions("tissue:position:query")

    public R positionDetail(String positionId) {
        return postionService.positionDetail(positionId);

    }


    /**
     * 禁用
     */
    @GetMapping("positionProhibit")
    @Operation(summary = "禁用")
    @Log(title = "禁用", businessType = BusinessType.UPDATE)
    @RequiresPermissions("tissue:position:dis")

    public R addQuery(String id, String enabled) {
        return areaService.prohibit(id, "点位", enabled);

    }

    /**
     * 修改
     */
    @PostMapping("updatePosition")
    @Operation(summary = "修改点位信息")
    @Log(title = "修改点位信息", businessType = BusinessType.UPDATE)
    @RequiresPermissions("tissue:position:edit")
    public R updatePosition(@RequestBody Position position) {
        return postionService.updatePosition(position);
    }

    /**
     * 根据点位id获取投资人列表
     */
    @GetMapping("/sharing")
    @Operation(summary = "根据点位id获取投资人列表")
    @Log(title = "根据点位id获取投资人列表")
    public R<List<PositionSharing>> getPositionSharing(@ApiParam(value = "计划组id") @NotNull(message = "点位id不能为空") String positionId) {
        return postionService.getPositionSharings(positionId);
    }

    /**
     * 获取启用的点位列表
     */
    @GetMapping("/list")
    @Operation(summary = "获取启用的点位列表")
    @Log(title = "获取启用的点位列表")
    public R<List<Position>> getPositionId(String cityName) {
        Position position = new Position();
        position.setCityName(cityName);
        return R.ok(postionService.getPositionIds(position));
    }

    @GetMapping("/info/byMachineId")
    @Operation(summary = "获取点位信息")
    public R<Position> getInfoByMachineId(@ApiParam(value = "机器id") String machineId) {
        return R.ok(postionService.getInfoByMachineId(machineId));
    }
    @GetMapping("/findByAreaId")
    @Operation(summary = "获取点位信息")
    public R<List<Position>> findByAreaId(@ApiParam(value = "区域ID") String areaId) {
        return R.ok(postionService.findByAreaId(areaId));
    }

    @GetMapping("/findPositionDraw")
    @Operation(summary = "获取抽奖点位")
    public R<List<Position>> findPositionDraw(@ApiParam(value = "区域ID") String areaId,
                                              @ApiParam(value = "区域ID") String positionId) {
        return R.ok(postionService.findPositionDraw(areaId, positionId));
    }

    /**
     * 获取启用的点位列表
     * 新增弹窗选点位使用
     */
    @GetMapping("/getPositionList")
    @Operation(summary = "获取启用的点位列表-新增弹窗选点位使用")
    @Log(title = "获取启用的点位列表")
    public R<List<Position>> getPositionList(@RequestParam("cityName") String cityName) {
        Position position = new Position();
        position.setCityName(cityName);
        return R.ok(postionService.getPositionIds(position));
    }


}
